defmodule ProgContest.ContestsTest do
  use ProgContest.DataCase
  use ProgContest.Fixtures

  describe "contests" do
    alias ProgContest.Contests.Contest

    test "list_contests/0 returns all contests" do
      contest = contest_fixture()
      assert Contests.list_contests() == [contest]
    end

    test "get_contest!/1 returns the contest with given id" do
      contest = contest_fixture()
      assert Contests.get_contest!(contest.id) == contest
    end

    test "create_contest/1 with valid data creates a contest" do
      assert {:ok, %Contest{} = contest} = Contests.create_contest(@valid_contest_attrs)
      assert contest.end_at == DateTime.from_naive!(~N[2010-04-17T14:00:00Z], "Etc/UTC")
      assert contest.name == "some name"
      assert contest.start_at == DateTime.from_naive!(~N[2010-04-17T14:00:00Z], "Etc/UTC")
    end

    test "create_contest/1 with invalid data returns error changeset" do
      assert {:error, %Ecto.Changeset{}} = Contests.create_contest(@invalid_contest_attrs)
    end

    test "update_contest/2 with valid data updates the contest" do
      contest = contest_fixture()
      assert {:ok, %Contest{} = contest} = Contests.update_contest(contest, @update_contest_attrs)
      assert contest.end_at == DateTime.from_naive!(~N[2011-05-18T15:01:01Z], "Etc/UTC")
      assert contest.name == "some updated name"
      assert contest.start_at == DateTime.from_naive!(~N[2011-05-18T15:01:01Z], "Etc/UTC")
    end

    test "update_contest/2 with invalid data returns error changeset" do
      contest = contest_fixture()
      assert {:error, %Ecto.Changeset{}} = Contests.update_contest(contest, @invalid_contest_attrs)
      assert contest == Contests.get_contest!(contest.id)
    end

    test "delete_contest/1 deletes the contest" do
      contest = contest_fixture()
      assert {:ok, %Contest{}} = Contests.delete_contest(contest)
      assert_raise Ecto.NoResultsError, fn -> Contests.get_contest!(contest.id) end
    end

    test "change_contest/1 returns a contest changeset" do
      contest = contest_fixture()
      assert %Ecto.Changeset{} = Contests.change_contest(contest)
    end
  end
end
